# Usage: python3 convert.py file_name.xlsx

import pandas as pd
import sys
def convert(somefile):
	with open(somefile,'r') as f:
		df = pd.read_excel("./"+somefile, dtype="str")
		reader = df.values
	
		allvcf = open(somefile+'.vcf','w',encoding='utf-8')
		i = 0
		for row in reader:
			print(row)
			name  =  str(row[0])
			print(name)
			tel   =  str(row[1])
			org   =  str(row[2])
			title =  str(row[3])
			note  =  str(row[4])
			if tel=="nan" or name=="nan": 
				print("no phone number")
			else:	
				allvcf.write('BEGIN:VCARD' + "\n")
				allvcf.write('VERSION:3.0' + "\n")
				allvcf.write('FN:' + name + "\n")
				allvcf.write('TEL;TYPE=CELL:' + tel + "\n")
				if org!="nan": 
					allvcf.write('ORG:' + org + "\n")
				if title!="nan": 
					allvcf.write('TITLE:' + title+ "\n")
				if note!="nan":
					allvcf.write('NOTE:' + note + "\n")

				allvcf.write('END:VCARD' + "\n")
				allvcf.write("\n")
				i += 1

		allvcf.close()
		print(str(i) + " vcf cards generated")


filename  = "vcf.xlsx"

convert(filename)
